import java.util.Vector;

class FuzzyRule{
    
    protected Vector<FuzzyVariable> v_variables;

    public FuzzyRule(){
	this.v_variables = new Vector();
    }//end constructor
    
    public void addVariable(FuzzyVariable fv){
	this.v_variables.add(fv);
    }

    public FuzzyVariable getFuzzyVariableAt(int pos){return this.v_variables.elementAt(pos);}

    public float membershipValue(Vector v_values){
	float result = 1;
	//--------- VARIABLES OF THE CURRENT RULE -----------
	for(int i=0;i<v_variables.size();i++){
	    FuzzyVariable fv = this.v_variables.elementAt(i);
	    float value = (Float) v_values.elementAt(i);
	    boolean belongs = false;
	 

	    if(fv.getNumberFuzzySets()>0){			
		//--------- FUZZY SETS OF THE CURRENT VARIABLE -------
		for(int j=0;j<fv.getNumberFuzzySets();j++){
		    FuzzySet fs = fv.getFuzzySetAt(j);
		    float tmp = fs.membershipValue(value);
		    if(tmp>0){
			belongs = true;
			if(tmp < result) result = tmp;
			break;
		    }			    
		}//end for
		//--------END FUZZY SETS -----------------------------
		if(!belongs){
		   return 0;
		}
	    }//end if
	}//end for variables		
	//------------END ANALYSIS OF VARIABLES FOR A RULE -----------
	return result;
    }//end membershipValue method
}//end class
